package com.own.component.util.database.model;

import com.own.component.util.database.base.BaseDatabaseFieldMapping;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * TableColumnModel
 *
 * @author chenxueli
 * @date 2022-10-15 14:09:31
 */
@Getter
@Setter
@Accessors(chain = true)
public class TableColumnModel implements Serializable {

    /**
     * S数据库字段名称
     */
    private String columnName;

    /**
     * 备注
     */
    private String comment;

    /**
     * 当前字段的类型
     */
    private String type;

    /**
     * 默认长度
     */
    private Long length;

    /**
     * 引入包的路径
     */
    private String path;

    /**
     * java类型
     */
    private String javaType;

    /**
     * ts类型
     */
    private String tsType;

    /**
     * 是否是外键
     */
    private Boolean isForeignKey;

    /**
     * 是否为空
     */
    private Boolean isNull;

    /**
     * 是否为主键
     */
    private Boolean isPrimaryKey;

    /**
     * 默认值
     */
    private String defaultValue;

    public void setMapping(BaseDatabaseFieldMapping mapping) {
        this.path = mapping.importPath();
        this.javaType = mapping.javaType();
        this.tsType = mapping.typescriptType();
        this.type = mapping.databaseType();
    }

}
